<template>
  <div>

    <div class="maincss">
      <el-row>
        <el-card>
          <!--          <searchBox title='一致性比对' :btn='btn' @func='showBtn' />-->
          <el-card class="filter-container" shadow="never">
            <el-row class="searchbox">
              <el-col span="1"> 一致性比对</el-col>
              <el-col span="3">
                <el-input v-model="queryParams.baseNo" class="input-width" placeholder="基准仪器编号"></el-input>
              </el-col>
              <el-col span="3">
                <el-input v-model="queryParams.contrastNo" class="input-width" placeholder="比对仪器编号"></el-input>
              </el-col>
              <el-col span="2">
                <el-select v-model="queryParams.type" placeholder="请选择比对类型">
                  <el-option
                    v-for="item in typeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-col>
              <el-col span="3">
                <el-date-picker
                  v-model="queryParams.createTime"
                  type="datetime"
                  placeholder="选择检验时间"
                >
                </el-date-picker>
              </el-col>
              <el-col span="1">
                <el-button @click="handleLoadAndQuery" type="primary">查询</el-button>
              </el-col>
              <el-col span="2">
                <el-button @click="handleOpenAdd" type="primary">新增</el-button>
              </el-col>
            </el-row>
          </el-card>
          <el-card class="gray-card no-border no-margin-top" shadow="never">
            <el-table
              v-loading="loading"
              :data="checkList"
              style="width: 100%;"
              @row-click="detailShow = true"
            >
              <el-table-column label="比对类型" align="center" prop="type">
                <template slot-scope="scope">
                  <span v-if="scope.row.type=='1'">设备间对比</span>
                  <span v-if="scope.row.type=='2'">检验科对比</span>
                </template>
              </el-table-column>
              <el-table-column label="基准仪器名称" align="center" prop="baseName" :show-overflow-tooltip="true"/>
              <el-table-column label="基准仪器编号" align="center" prop="baseNo"/>
              <el-table-column label="比对仪器名称" align="center" prop="contrastName" :show-overflow-tooltip="true"/>
              <el-table-column label="比对仪器编号" align="center" prop="contrastNo" :show-overflow-tooltip="true"/>
              <el-table-column label="所属科室" align="center" prop="deptName"/>
              <el-table-column label="操作人" align="center" prop="createBy"/>
              <el-table-column label="比对时间" align="center" prop="createTime"/>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleDetail(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >详情
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleEdit(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >编辑
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleDownload(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >下载
                  </el-button>
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleDelete(scope.row)"
                    v-hasPermi="['monitor:online:forceLogout']"
                  >删除
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </el-card>
          <div class="pagination-container">

            <pagination v-show="total>0" :total="total"
                        :page.sync="queryParams.pageNum"
                        :limit.sync="queryParams.pageSize"
                        @pagination="handleLoadAndQuery"/>
          </div>
        </el-card>
      </el-row>
      <el-drawer
        :title="title"
        :visible.sync="addShow"
        size="65%"
      >
        <addEdit
          ref="AddRef"
          :disabled="disabled"
          @close="handleClose"/>
      </el-drawer>
    </div>
  </div>
</template>

<script>

import addEdit from './addEdit'
import {queryPage, cancelById} from "@/api/business/instrumentComparison"
import {parseTime} from '@/utils/ruoyi'
import {listInstrumentComparisonItems} from "@/api/business/instrumentComparisonItems"

export default {
  name: 'maintenanceInfo',
  components: {
    addEdit
  },
  data() {
    return {
      title: '新增',
      addShow: false,
      detailShow: false,
      disabled: false,
      checkList: [],
      loading: false,
      typeList: [
        {
          label: '全部',
          value: ''
        },
        {
          label: '设备间对比',
          value: '1'
        },
        {
          label: '检验科对比',
          value: '2'
        }
      ],
      status: [],
      inspectionRsult: [],
      value: '',
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        baseNo: '',
        contrastNo: '',
        createTime: '',
        type: ''
      }
    }
  },
  watch: {},
  created() {
    this.$nextTick(() => {
      this.handleLoadAndQuery()
    })
  },
  methods: {
    handleOpenAdd() {
      this.addShow = true
      this.disabled = false
      this.title = '新增'
    },
    handleEdit(row) {
      this.addShow = true
      this.disabled = false
      this.title = '编辑'
      this.$nextTick(() => {
        listInstrumentComparisonItems({
          comparisonId: row.id,
          pageNum: 1,
          pageSize: 100
        }).then((res) => {
          this.$refs.AddRef.handleData(row, res.rows)
        })
      })
    },
    handleDetail(row) {
      this.addShow = true
      this.disabled = true
      this.title = '详情'
      this.$nextTick(() => {
        listInstrumentComparisonItems({
          comparisonId: row.id,
          pageNum: 1,
          pageSize: 100
        }).then((res) => {
          this.$refs.AddRef.handleData(row, res.rows)
        })
      })
    },
    handleDownload(row) {

    },
    handleDelete(row) {
      cancelById(row.id).then((res) => {
        this.$message.success('操作成功')
        this.handleLoadAndQuery()
      })
    },
    handleLoadAndQuery() {
      if (this.queryParams.createTime) {
        this.queryParams.createTime = parseTime(this.queryParams.createTime)
      } else {
        this.queryParams.createTime = ''
      }
      this.checkList = []
      this.loading = true
      queryPage(this.queryParams).then((res) => {
        if (res) {
          this.loading = false
          this.checkList = res.records
          this.total = res.total
        }
      })
      .catch(() => {
        this.loading = false
      })
    },
    handleClose() {
      this.addShow = false
      this.disabled = false
      this.title = '新增'
      this.handleLoadAndQuery()
    }
  }
}
</script>
